<template>
	<view class="content">
		<view class="list" @click="learningdetails(item.courseId)" v-for="item,index in itemList"
			v-if="itemList.length>0">
			<view class="img">
				<image :src="item.courseCover" mode=""></image>
				<!-- 	<view class="free">
					免费试看
				</view> -->
			</view>
			<view class="title">
				<view class="name">
					{{item.courseTitle}}
				</view>
				<view class="progressbar" v-if="item.progress">
					<u-line-progress :percentage="item.progress" activeColor="#FF9C33"></u-line-progress>
				</view>
				<view class="progressbar" v-if="!item.progress"> 未开始 </view>
			</view>
		</view>
		<view class="" v-else style="text-align: center;margin-top: 500rpx;font-size: 36rpx;"> 您的学习列表暂无课程~ </view>
	</view>
</template>
<script>
	import {
		orderPage
	} from "../../request/api.js"
	import {
		idCard
	} from "../../uni_modules/uview-plus/libs/function/test.js";
	export default {
		data() {
			return {
				selectedIdx: 10,
				itemList: [],
			};
		},
		onLoad(options) {},
		onShow() {
			let isLogin = uni.getStorageSync('token')
			if (!isLogin) {
				uni.showToast({
					title: '请先登录',
					icon: "none"
				})
				setTimeout(() => {
					uni.switchTab({
						url: '/pages/my/index'
					})
				}, 1500)
				return;
			}
			this.orderPagea()
		},
		methods: {
			orderPagea() {
				orderPage({
					status: 2,
					memberId: uni.getStorageSync('userInfo').id
				}).then(res => {
					console.log(res);
					this.itemList = res.result.records
				})
			},
			learningdetails(id) {
				uni.navigateTo({
					url: '/pages/study/learningdetails?id=' + id
				})
			},
			a() {
				uni.requestPayment({
					provider: 'wxpay',
					orderInfo: JSON.parse(res.data),
					success: function(res) {
						console.log('success:' + JSON.stringify(res));
						if (res.errMsg == "requestPayment:ok") {
							uni.navigateTo({
								url: "../pay_success/pay_success?id=" + _this.id
							})
						} else {
							console.log(res.msg)
							toast(res.msg)
						}
					},
					fail: function(err) {
						console.log('fail:' + JSON.stringify(err));
						// toast(res.msg)
					},
				});
			},
			b() {
				let ressuccess = JSON.parse(responts.result)
				uni.requestPayment({
					'timeStamp': ressuccess.timeStamp,
					'nonceStr': ressuccess.nonceStr,
					'package': ressuccess.package,
					'signType': ressuccess.signType,
					'paySign': ressuccess.paySign,
					'success': function(res) {
						console.log(res)
						uni.showModal({
							title: '提示',
							content: "支付成功！",
							showCancel: false,
							success: function(res) {
								if (that.type == 2) {
									uni.navigateBack()
								} else {
									uni.redirectTo({
										url: '/pages/orderdetails/index?ordernum=' + that
											.orderid,
									})
								}
							}
						})
					},
					'fail': function(res) {
						console.log(res, '失败原因')
						uni.showModal({
							title: '提示',
							content: "支付失败！",
							showCancel: false,
							success: function(res) {
								if (that.type == 2) {
									uni.navigateBack()
								} else {
									uni.redirectTo({
										url: '/pages/orderdetails/index?ordernum=' + that
											.orderid,
									})
								}
								that.dianjiflag = true
							}
						})
					}
				})
			}
		},
	};
</script>
<style scoped lang="less">
	.content {
		width: 100%;
		min-height: 100vh;
		box-sizing: border-box;
		padding: 16rpx;
		padding-top: 20rpx;
		background: #F7F7F7;
		// padding-top: 20rpx;
		padding-bottom: 250rpx;
	}

	.list {
		display: flex;
		align-items: center;
		padding: 44rpx 52rpx 28rpx 18rpx;
		background: #ffffff;
		border-radius: 22rpx;
		margin-bottom: 20rpx;

		.img {
			width: 328rpx;
			height: 166rpx;
			position: relative;

			image {
				width: 328rpx;
				height: 166rpx;
			}

			.free {
				position: absolute;
				top: 15rpx;
				left: 15rpx;
				width: 76rpx;
				height: 30rpx;
				border-radius: 16rpx;
				background: #f05555;
				color: #ffffff;
				text-align: center;
				line-height: 30rpx;
				font-size: 16rpx;
				font-weight: 400;
			}
		}

		.title {
			width: 100%;
			// height: 166rpx;
			margin-left: 20rpx;
			position: relative;

			.name {
				color: #0c0c0c;
				font-size: 32rpx;
				font-weight: 700;
				margin-bottom: 78rpx;
				// position: absolute;
				// top: 0;
			}

			.progressbar {
				// position: absolute;
				// bottom: 0;
				// z-index: 10;
			}
		}
	}
</style>